package  
{
	/**
	 * ...
	 * @author Paul Forest
	 */
	public class Person 
	{
		public var firstName:String = "FIRST NAME";
		public var lastName:String = "LAST NAME";
		public var email:String = "";
		public var url:String = "";
		public var hasSkills:Vector.<String> = new Vector.<String>();
		public var wantsSkills:Vector.<String> = new Vector.<String>();
		public var matches:Vector.<Match> = new Vector.<Match>();
		
		public function Person(firstName:String, lastName:String, email:String, url:String, hasSkills:Vector.<String>, wantsSkills:Vector.<String>) 
		{
			this.firstName = firstName;
			this.lastName = lastName;
			this.hasSkills = hasSkills;
			this.wantsSkills = wantsSkills;
			this.email = email;
			this.url = url;
		}
		
		public function getMatchScoreTo(other:Person):int {
			var score:int = 0;
			
			var myHasLen:int = hasSkills.length;
			var herHasLen:int = other.hasSkills.length;
			
			var i:int;
			
			//check if we meet the other person's needs
			for (i = 0; i < herHasLen; i++) {
				if (doesWantSkill(other.hasSkills[i])) {
					score ++;
				}
			}

			//check if the other person meets our needs
			for (i = 0; i < myHasLen; i++) {
				if (other.doesWantSkill(hasSkills[i])) {
					score ++;
				}
			}
			
			//trace("      isAMatchTo(): score="+score+" other=" + other + " this=" + this);
			return score;
		}
		
		public function doesWantSkill(skill:String):Boolean {
			var myWantsLen:int = wantsSkills.length;
			skill = skill.toLowerCase();
			for (var i:int = 0; i < myWantsLen; i++) {
				if (wantsSkills[i].toLowerCase() == skill) {
					return true;
				}
			}
			return false;
		}
		
		public function doesMatchExistWith(other:Person):Boolean {
			var result:Boolean = false;
			matches.forEach(function (match:Match, index:int, vector:Vector.<Match>):void {
				if (match.person1 == other || match.person2 == other) {
					result = true;
				}
			}, this);
			return result;
		}
		
		public function isBusyInRound(round:int):Boolean
		{
			var len:int = matches.length;
			for (var i:int = 0; i < len; i++) {
				if (matches[i].round == round) {
					return true;
				}
			}
			return false;
		}		
		
		public function toString():String {
			return "Person: " 
				+ " matches=" + matches.length
				+ " firstName="+firstName
				+ " lastName=" + lastName
				+ " hasSkills=[" + hasSkills.join(",") + "]"
				+ " wantsSkills=[" + wantsSkills.join(",") + "]"
				
				//+ " matches=[" + matches.join(",") + "]"
				;
		}
		
	}

}